home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / Librarys / MMULib / C_Sources / MuSetCacheMode.c < prev    next >
C/C++ Source or Header  |  1999-11-28  |  22KB  |  470 lines

  1. /*****************************************************************
  2.  ** MuSetCacheMode                                              **
  3.  **                                                             **
  4.  ** Reprogram MMU tables selectively.                           **
  5.  ** Release 40.7, © 1999 THOR-Software inc.                     **
  6.  ** 28.11.1999 Thomas Richter                                   **
  7.  *****************************************************************/
  8.  
  9. /// Includes
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/ports.h>
  13. #include <dos/dos.h>
  14. #include <mmu/mmubase.h>
  15. #include <mmu/context.h>
  16. #include <mmu/mmutags.h>
  17. #include <workbench/startup.h>
  18.  
  19. #include <thor/conversions.h>
  20.  
  21. #include <proto/exec.h>
  22. #include <proto/mmu.h>
  23. #include <proto/dos.h>
  24. #include <proto/icon.h>
  25. #include <string.h>
  26. ///
  27. /// Defines
  28. #define STRINGDATE "28.11.99"
  29. #define STRINGVERSION "40.7"
  30. #define TEMPLATE "ADDRESS=FROM/A,SIZE/A,COPYBACK/S,WRITETHROUGH/S,NOCACHESERIALIZED=CACHEINHIBIT/S,NONSERIAL/S,NOCACHE=IMPRECISE/S,VALID/S,INVALID/S,BLANK/S,IO=IOSPACE/S,NOIO=NOIOSPACE/S,ROM/S,NOROM/S,WRITEPROTECTED/S,NOTWRITEPROTECTED/S,USERONLY/S,SUPERVISORONLY/S,VERBOSE/S"
  31. #define CACHEFLAGS (MAPP_CACHEINHIBIT|MAPP_NONSERIALIZED|MAPP_IMPRECISE|MAPP_COPYBACK)
  32. #define ROMFLAGS (MAPP_ROM|MAPP_WRITEPROTECTED)
  33.  
  34. #define OPT_ADDRESS 0
  35. #define OPT_SIZE 1
  36. #define OPT_COPYBACK 2
  37. #define OPT_WRITETHROUGH 3
  38. #define OPT_NOCACHE 4
  39. #define OPT_NOCACHESERIALIZED 5
  40. #define OPT_NOCACHEIMPRECISE 6
  41. #define OPT_VALID 7
  42. #define OPT_INVALID 8
  43. #define OPT_BLANK 9
  44. #define OPT_IO 10
  45. #define OPT_NOIO 11
  46. #define OPT_ROM 12
  47. #define OPT_NOROM 13
  48. #define OPT_WRITEPROTECTED 14
  49. #define OPT_NOTWRITEPROTECTED 15
  50. #define OPT_USERONLY 16
  51. #define OPT_SUPERVISORONLY 17
  52. #define OPT_VERBOSE 18
  53. #define OPT_WINDOW 19
  54. #define OPT_COUNT 20
  55.  
  56. #define WHICH_ALL       3
  57. #define WHICH_USER      1
  58. #define WHICH_SUPER     2
  59. ///
  60. /// Statics
  61. struct MMUBase *MMUBase;
  62. struct DosLibrary *DOSBase;
  63. struct ExecBase *SysBase;
  64. struct Library *IconBase;
  65. ///
  66. /// Protos
  67. int __asm __saveds main(void);
  68. int SetCacheMode(ULONG from,ULONG size,ULONG flags,ULONG mask,ULONG which);
  69. struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp);
  70. ///
  71.  
  72. char version[]="$VER: MuSetCacheMode " STRINGVERSION " (" STRINGDATE ") © THOR";
  73.  
  74. /// main
  75. int __asm __saveds main(void)
  76. {
  77. LONG args[OPT_COUNT];
  78. struct RDArgs *rd,*myrd;
  79. struct Process *proc;
  80. int rc=20;
  81. LONG err;
  82. struct WBStartup *msg;
  83. BPTR oldout;
  84. struct MsgPort *oldconsole;
  85. LONG flags,which;
  86. char *whichmsg;
  87. int from=0,size=0;
  88. ULONG mask;
  89. char flagsmsg[256];
  90.  
  91.  
  92.         SysBase=*((struct ExecBase **)(4L));
  93.  
  94.         memset(args,0,sizeof(LONG)*OPT_COUNT);
  95.         flagsmsg[0]='\0';                       /* Clear this string */
  96.  
  97.         /* Wait for the workbench startup, if any */
  98.         proc=(struct Process *)FindTask(NULL);
  99.  
  100.         if (!(proc->pr_CLI)) {
  101.                 WaitPort(&(proc->pr_MsgPort));
  102.                 msg=(struct WBStartup *)GetMsg(&(proc->pr_MsgPort));
  103.         } else  msg=NULL;
  104.  
  105.         if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
  106.                 if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",41L)) {
  107.  
  108.                         err=ERROR_REQUIRED_ARG_MISSING;
  109.  
  110.                         myrd=NULL;      /* reset the temporary ReadArgs */
  111.                         oldout=NULL;
  112.                         oldconsole=NULL;
  113.                         if (msg) {
  114.                                 oldout=SelectOutput(NULL);
  115.                                 oldconsole=SetConsoleTask(NULL);
  116.                                 rd=ReadTTArgs(msg,args,&myrd);
  117.                         } else  rd=ReadArgs(TEMPLATE,args,NULL);
  118.  
  119.                         if (rd) {
  120.                                 if (!GetMMUType()) {
  121.                                         Printf("MuSetCacheMode requires a working MMU.\n");
  122.                                         err=10;
  123.                                 } else {
  124.  
  125.                                         err=0;
  126.  
  127.                                         if (args[OPT_ADDRESS]==NULL || args[OPT_SIZE]==NULL)
  128.                                                 err=ERROR_REQUIRED_ARG_MISSING;
  129.  
  130.                                         if (err==0) {
  131.  
  132.                                                 if (!StrToL((char *)(args[OPT_ADDRESS]),NULL,&from,16))
  133.                                                         err=ERROR_BAD_NUMBER;
  134.  
  135.                                                 if (!StrToL((char *)(args[OPT_SIZE]),NULL,&size,16)) {
  136.                                                         err=ERROR_BAD_NUMBER;
  137.                                                 } else if (size==0) err=ERROR_BAD_NUMBER;
  138.  
  139.  
  140.                                         }       
  141.                                         if (err==0) {
  142.  
  143.                                                 flags=0;
  144.                                                 mask=0;
  145.  
  146.                                                 if (args[OPT_VALID]) {
  147.                                                         mask |= MAPP_INVALID | MAPP_BLANK | MAPP_REPAIRABLE;
  148.                                                         strcat(flagsmsg,"valid ");
  149.                                                 }
  150.                                                 if (args[OPT_IO]) {
  151.                                                         flags &= ~CACHEFLAGS;
  152.                                                         flags |= MAPP_IO|MAPP_CACHEINHIBIT;
  153.                                                         mask |= MAPP_IO|CACHEFLAGS;
  154.                                                         strcat(flagsmsg,"IO space ");
  155.                                                 }
  156.                                                 if (args[OPT_NOIO]) {
  157.                                                         mask |= MAPP_IO;
  158.                                                         flags &= ~MAPP_IO;
  159.                                                         strcat(flagsmsg,"memory space ");
  160.                                                 }
  161.                                                 if (args[OPT_COPYBACK]) {
  162.                                                         flags &= ~CACHEFLAGS;
  163.                                                         flags |= MAPP_COPYBACK;
  164.                                                         mask |= CACHEFLAGS;
  165.                                                         strcat(flagsmsg,"copyback ");
  166.                                                 }
  167.                                                 if (args[OPT_WRITETHROUGH]) {
  168.                                                         flags &= ~CACHEFLAGS;    /* writethrough is the default */
  169.                                                         mask |= CACHEFLAGS;
  170.                                                         strcat(flagsmsg,"writethrough ");
  171.                                                 }
  172.                                                 if (args[OPT_NOCACHE]) {
  173.                                                         flags &= ~CACHEFLAGS;
  174.                                                         flags |= MAPP_CACHEINHIBIT;
  175.                                                         mask |= CACHEFLAGS;
  176.                                                         strcat(flagsmsg,"cacheinhibit ");
  177.                                                 }
  178.                                                 if (args[OPT_NOCACHESERIALIZED]) {
  179.                                                         flags &= ~CACHEFLAGS;
  180.                                                         flags |= MAPP_CACHEINHIBIT | MAPP_NONSERIALIZED;
  181.                                                         mask |= CACHEFLAGS;
  182.                                                         if (!args[OPT_NOCACHEIMPRECISE]) {
  183.                                                                 strcat(flagsmsg,"cacheinhibit non-serialized ");
  184.                                                         }
  185.                                                 }
  186.                                                 if (args[OPT_NOCACHEIMPRECISE]) {
  187.                                                         flags &= ~CACHEFLAGS;
  188.